<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="/wondershare/js/jquery.js"></script>
<link href="/wondershare/styles/main.css" rel="stylesheet" type="text/css" />
<link href="/wondershare/styles/general.css" rel="stylesheet" type="text/css" />
<style type="text/css">
#myform input{margin-right:10px;}
</style>
<script type="text/javascript">
//note 整站搜索
function searchFun(){
	var k = $("#keyword").val();
	if( !k ){
		alert("关键字不能为空！");	
	}else{
		$("#myform").attr("method","get");
		$("#myform").submit();	
	}
}
//note 整站替换
function replaceFun(){
	var k = $("#keyword").val();
	var r = $("#replace").val();
	if( !k || !r ){
		alert("关键字和替换内容不能为空！")	
	}else{
		var ret = window.confirm("整站替换内容有风险，您真的要整站替换内容吗？");
		if( ret ){
			$("#keyword").val( $("#keyword").val() );
			$("#replace").val( $("#replace").val() );
			$("#type").val("replace_all");
			$("#myform").attr("method","post");
			$("#myform").submit();
		}
	}
}

//note 单个替换
function replaceOne( id ){
	var k = $("#keyword").val();
	var r = $("#replace").val();
	var w = $("#w").val();
	var s = $("#s").val();
	
	if( !k || !r ){
		alert("关键字和替换内容不能为空！")	
	}else{
		var ret = window.confirm("您真的要替换该文章标题或内容中的关键字吗？");	
		if( ret ){
			$.post('?action=site_search',{'ispost':1,'type':'replace_one','ar_id':id,'keyword':k,'replace':r,'w':w,'s':s},function(data){
				//alert(data);
				if( parseInt( data ) ){
					alert("替换成功！");
					$("#tr_"+id).remove();
				}else{
					alert("替换失败！");
				}
			});
		}
	}
}

//note 部分替换
function replaceSome(){
	var k = $("#keyword").val();
	var r = $("#replace").val();
	var w = $("#w").val();
	var s = $("#s").val();
	
	if( !k || !r ){
		alert("关键字和替换内容不能为空！")	
	}else{
		var ret = window.confirm("您真的要替换该文章标题或内容中的关键字吗？");	
		if( ret ){
			$("#_keyword").val( $("#keyword").val() );
			$("#_replace").val( $("#replace").val() );
			$("#_w").val( $("#w").val() );
			$("#_s").val( $("#s").val() );
			$("#myform_2").submit();
		}
	}
}

//note 展开与收起
function taggle( id ){
	var a = $("#taggle_"+id).html();
	if( a == '展开' ){
		$("#wrap_"+id).css("overflow","");
		$("#wrap_"+id).css("height","");
		$("#taggle_"+id).html("收起");
	}else{
		$("#wrap_"+id).css("overflow","hidden");
		$("#wrap_"+id).css("height","16px");
		$("#taggle_"+id).html("展开");
	}
}
</script>
</head>

<body>
<h1> <span id="search_id" class="action-span1"> 整站搜索替换 </span>
  <div style="clear:both"></div>
</h1>
<form id="myform" name="myform">
  <img height="22" border="0" width="26" alt="SEARCH" src="images/icon_search.gif"> 
  关键字：<input type="text" size="40" id="keyword" name="keyword" value='<{$keyword}>'/>
  <select name="w" id="w">
  <option value="1" <{if $w==1}>selected="selected"<{/if}>>区分大小写</option>
  <option value="2" <{if $w==2}>selected="selected"<{/if}>>不区分大小写</option>
  </select>&nbsp;&nbsp;
  <select name="s" id="s">
  <option value="2" <{if $s==2}>selected="selected"<{/if}>>搜源文件</option>
  <option value="1" <{if $s==1}>selected="selected"<{/if}>>搜文本</option>
  </select>&nbsp;&nbsp;
  <input type="button" class="button"  name="search" value="整站搜索" onclick="searchFun()" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
  替换为：<input type="text" size="40" id="replace" name="replace" value="<{$replace}>" />
  <input type="button" class="button"  name="search" value="整站替换" onclick="replaceFun()" />
  <input type="hidden" name="action" value="site_search" />
  <input type="hidden" name="w_type" value="<{$w_type}>" />
  <input type="hidden" name="ar_id_list" value="<{$ar_id_list}>" />
  <input type="hidden" name="type" id="type" value="search" />
</form>
<form method="post" id="myform_2" name="myform_2">
<table width="100%" cellspacing="1" cellpadding="2" id="list-table" class="list-div">
<tbody>
  <tr>
    <th width="60">ID</th>
    <th width="30%">标题</th>
    <th>内容</th>
    <th>文本 / html标签</th>
    <th width="60">操作</th>
  </tr>
</tbody>
<{foreach from=$data item=v}>
<tr id="tr_<{$v.ar_id}>">
	<td align="left" style="padding-left:10px;"><input type="checkbox" name="ID[]" value="<{$v.ar_id}>"/><span style="width:20px;"><{$v.ar_id}></span></td>
    <td style="padding-left:6px;"><{$v.ar_title}></td>
    <td><div id="wrap_<{$v.ar_id}>" style="height:16px;width:90%;overflow:hidden;float:left;"><{$v.ar_content}></div><div style="float:left">...[<a id="taggle_<{$v.ar_id}>" href="javascript:taggle(<{$v.ar_id}>);">展开</a>]</div></td>
    <td align="center"><{$v.times_1}> / <{$v.times_2}></td>
    <td align="center"><a href="article.php?action=index&act=edit&ar_id=<{$v.ar_id}>&w_type=<{$w_type}>">编辑</a> | <a href="javascript:replaceOne(<{$v.ar_id}>);">替换</a></td>
</tr>
<{/foreach}>
<tr>
<td>&nbsp;&nbsp;&nbsp;<input type="checkbox" onclick="var v=document.getElementsByName('ID[]');if(this.checked){for(i=0;i<v.length;i++)v[i].checked=true;}else{for(i=0;i<v.length;i++)v[i].checked=false;}" />全选</td>
<td colspan="4" style="padding-left:6px;"><input type="button" onclick="replaceSome()" value="替换" />&nbsp;&nbsp;&nbsp;&nbsp;<{$pages}>&nbsp;&nbsp;&nbsp; 共有 <span id="total"><{$num}></span>条记录</td>
</tr>
</table>
<input type="hidden" name="keyword" id="_keyword" />
<input type="hidden" name="replace" id="_replace" />
<input type="hidden" name="w" id="_w" />
<input type="hidden" name="s" id="_s" />
<input type="hidden" name="ispost" value="1" />
<input type="hidden" name="type" value="replace_some" />
</form>
</body>
</html>
